package is95powercontrol;
import javafx.scene.CustomNode;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.part.NumberAxis;
import javafx.scene.chart.part.Side;
import javafx.scene.text.Font;
import javafx.scene.Node;
import javafx.util.Math;



/**
 * @author azaleski
 */
 public class PilotMonitor extends CustomNode {

     override protected function create () : Node {
         pilotSignalLineChart;
     }

     public-init var width = 300;
     public-init var height = 280;
     public var x : Number;
     public var y : Number;

     public var mobileStationX : Number;
     public var mobileStationY : Number;

     var pilotSignalLineChartSeries : LineChart.Series[] = [
         LineChart.Series { name: "Moc odbierana sygnalu pilota [BTS -> Mobile]" }
     ];

     var pilotSignalLineChart = LineChart {

         translateX: 10
         translateY: 10

         showSymbols: false
         legendSide: Side.TOP

         data: pilotSignalLineChartSeries


         xAxis: NumberAxis {
             lowerBound: 1
             upperBound: 100
             tickUnit: 10
             label: "Miliseconds"


             labelFont: Font { size: 10 }
             tickLabelTickGap: 10
             tickLabelFont: Font { size: 9 }
             labelTickGap: 10
             tickMarkLength: 10
         }
         yAxis: NumberAxis {
             lowerBound: -40
             upperBound: 30
             tickUnit: 10
             label: "[dB]"
             labelFont: Font { size: 10 }
             tickLabelTickGap: 10
             tickLabelFont: Font { size: 9 }
             labelTickGap: 10
             tickMarkLength: 10
             tickMarkVisible: false
         }
         height: height
         width: width
         layoutX : x
         layoutY: y
     }


     var pilotIndex = 0;
     var value = 0.0;

     public function updatePilot() {
         value = 20*Math.log10(Math.sqrt((-Math.log(1-(Math.random())))));

         insert LineChart.Data {
             xValue: pilotIndex
             yValue: value
         } into pilotSignalLineChartSeries[0].data;

         pilotIndex += 1;
         if(pilotIndex >= pilotSignalLineChart.xAxis.upperBound) {
             /**
              * Shift line chart
              */
             pilotSignalLineChart.xAxis.lowerBound += 1;
             pilotSignalLineChart.xAxis.upperBound += 1;

             // Delete initial data
             delete pilotSignalLineChartSeries[0].data[0];
         }
     }
 }
